package com.sywb.chuangyebao.view;

import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sywb.chuangyebao.R;
import com.sywb.chuangyebao.contract.SplashContract;

import org.bining.footstone.utils.StatusBarUtils;
import org.bining.footstone.utils.ToastUtils;

import butterknife.BindView;

/**
 * 开屏页
 */
public class SplashActivity extends BaseStatisticsActivity<SplashContract.Presenter> implements SplashContract.SplashView {

    @BindView(R.id.splash)
    ImageView splash;
    @BindView(R.id.tv_jump)
    TextView tvJump;

    @Override
    public int getLayoutId(Bundle bundle) {
        return R.layout.activity_splash;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public void initView(Bundle bundle) {
        StatusBarUtils.setColorByTransparent(this);
        tvJump.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mPresenter.cancelCountDown();
                mPresenter.toIntentOther();
            }
        });
    }

    @Override
    public void initPresenter() {
        mPresenter.initPresenter(this);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (mPresenter != null) {
            mPresenter.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

    @Override
    public void onBackPressed() {
        exit();
    }

    @Override
    public void exit() {
        long newClickTime = System.currentTimeMillis();
        if (newClickTime - oldClickTime < 1000) {
            moveTaskToBack(false);
        } else {
            oldClickTime = newClickTime;
            ToastUtils.show(mActivity, R.string.app_exit);
        }
    }

    @Override
    public boolean useSwipeFinish() {
        return false;
    }

    @Override
    public boolean useWindowBackground() {
        return false;
    }

    @Override
    public boolean useLightMode() {
        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
    }

    @Override
    public TextView getJumpView() {
        return tvJump;
    }

    @Override
    public ImageView getAdView() {
        return splash;
    }
}
